import time

def write_time_to_file(file_path):
    # 开始时间
    start_time = time.time()
    end_time = start_time + 10 * 60  # 10分钟后的结束时间

    with open(file_path, 'a') as file:
        while time.time() < end_time:
            current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            file.write(current_time + '\n')
            file.flush()  # 确保每次写入后都保存文件
            time.sleep(1)  # 暂停1秒

if __name__ == "__main__":
    write_time_to_file("C:\\test.txt")